<?php $this->beginClip('pagetitle'); ?>Helper<?php $this->endClip(); ?>

<link rel="stylesheet" href="/resources/common/bootstrap-3.3.4/css/bootstrap.min.css" />

<div class="am-container">
    <div class="am-g">
        <div class="am-u-sm-12">
            <table class="table" id="disp-panel" style="display: block; height: 90%;">
                <tr>
                    <th>时间</th>
                    <th>码密文</th>
                    <th>码解密</th>
                    <th>扫码结果</th>
                </tr>
            </table>
       </div>
    </div>
</div>

<button id="scan-btn" style="font-size: 13px; color: #00b263;border-radius: 5px; margin-top: 110px; width: 100%; padding: 12px 45px 7px 45px; background: transparent !important; border: solid 1px #00b263;" type="button" class="btn">扫码</button>

<script>
    $(document).ready(function(){
		<?php app()->WxInterface->initWxJsConfig(array(
			'scanQRCode'
		), true, false); ?>
        
    	wx.ready(function(){
    		var scanQRCode = function(){
    			wx.scanQRCode({
                    needResult: 1, 
                    scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
                    success: function (res) {
                    	var result = res.resultStr; 
                    	$.ajax({
							type: 'get', 
							url: '/pay/helper', 
							data: {
								coderesult: result
							}, 
							success:function(ret){
								var li = $('<tr />');
								li.append('<td>'+ ret.time +'</td>');
								li.append('<td>'+ ret.id_merchant_en +'</td>');
								li.append('<td>'+ ret.id_merchant_de +'</td>');
								li.append('<td>'+ result +'</td>');
								$('#disp-panel').append(li);

								var id_merchant_de = ret.id_merchant_de;
								if(
									(id_merchant_de >= 5019 && id_merchant_de <= 5117) || 
									(id_merchant_de >= 5167 && id_merchant_de <= 5217) || 
									(id_merchant_de >= 5618 && id_merchant_de <= 5717) || 
									(id_merchant_de >= 5718 && id_merchant_de <= 5817) || 
									(id_merchant_de >= 5828 && id_merchant_de <= 5906) || 
									(id_merchant_de >= 5918 && id_merchant_de <= 6017) 
								){
									confirm('可用: ' + id_merchant_de);
								}else{
									confirm('不不不不不可用: ' + id_merchant_de);
								}

				        		scanQRCode();
							}, 
							dataType: 'json'
                        })
                    }
                });
        	}
        	
        	$('#scan-btn').on('click', function(){
        		scanQRCode();
            });
        });
    });
</script>